#include "syscall.h"

/* GLOBAL VARIABLES */
	int lock1;
	int lock2;
	int lock3;
	int cond1;
	int	cond2;
	int cond3;
	int mv1;
	int mv2;
	int mv3;

void testInitializer(){

	Printing("initializing everything!\n", ConsoleOutput, 0, 0);
	
	lock1 = 0;
	lock2 = 0;
	lock3 = 0;
	cond1 = 0;
	cond2 = 0;
	cond3 = 0;
	mv1 = 0;
	mv2 = 0;
	mv3 = 0;
	
	lock1 = CreateLock("lock1", 5);
	Printing("lock1 created!\n", ConsoleOutput, 0, 0);
	if(lock1 == -1){
		Printing("Error when trying to create lock 1!\n", ConsoleOutput, 0, 0);
	}
	lock2 = CreateLock("lock2", 5);
	Printing("lock2 created!\n", ConsoleOutput, 0, 0);
	if(lock2 == -1){
		Printing("Error when trying to create lock 2!\n", ConsoleOutput, 0, 0);
	}
	lock3 = CreateLock("lock3", 5);
	Printing("lock3 created!\n", ConsoleOutput, 0, 0);
	if(lock2 == -1){
		Printing("Error when trying to create lock 3!\n", ConsoleOutput, 0, 0);
	}
	
	cond1 = CreateCondition("cond1", 5);
	Printing("cond1 created!\n", ConsoleOutput, 0, 0);
	if(cond1 == -1){
		Printing("Error when trying to create cond1!\n", ConsoleOutput, 0, 0);
	}
	cond2 = CreateCondition("cond2", 5);
	Printing("cond2 created!\n", ConsoleOutput, 0, 0);
	if(cond2 == -1){
		Printing("Error when trying to create cond2!\n", ConsoleOutput, 0, 0);
	}
	cond3 = CreateCondition("cond3", 5);
	Printing("cond3 created!\n", ConsoleOutput, 0, 0);
	if(cond3 == -1){
		Printing("Error when trying to create cond3!\n", ConsoleOutput, 0, 0);
	}

	mv1 = CreateMonitor("mv1", 3);
	Printing("mv1 created!\n", ConsoleOutput, 0, 0);
	if(mv1 == -1){
		Printing("Error when trying to create mv1!\n", ConsoleOutput, 0, 0);
	}
	mv2 = CreateMonitor("mv2", 3);
	Printing("mv2 created!\n", ConsoleOutput, 0, 0);
	if(mv2 == -1){
		Printing("Error when trying to create mv2!\n", ConsoleOutput, 0, 0);
	}
	mv3 = CreateMonitor("mv3", 3);
	Printing("mv3 created!\n", ConsoleOutput, 0, 0);
	if(mv3 == -1){
		Printing("Error when trying to create mv3!\n", ConsoleOutput, 0, 0);
	}
}

	
void menu(){
	char * choice;

	Write("Please choose of the following options.\n", 40, ConsoleOutput);
	Write("1. testExec\n", 12, ConsoleOutput);
	Write("2. Simple lock, condition, and monitor test.\n", 45, ConsoleOutput);
	Write("3. Broadcast test.\n", 19, ConsoleOutput);
	Write("4. Acquire lock that doesn't exist.\n", 36, ConsoleOutput);
	Write("5. Releasing an unacquired lock.\n", 33, ConsoleOutput);/*
	Write("6. Acquiring a destroyed lock.\n", 31, ConsoleOutput);
	Write("7. Acquiring a lock twice.\n", 27, ConsoleOutput);
	Write("8. Create Condition Test\n", 25, ConsoleOutput);
	Write("9. More...\n", 11, ConsoleOutput);
	*/

	Write("\n\nNote: only the first digit that you enter will be read.  \nFor example, input 456 will be read as choice 4.\n", 109, ConsoleOutput);
	Read(choice, 1, ConsoleInput);
	
	if(*choice == '1'){
		Exec("../test/testExec", 16);
		Exit(0);
	}
	else if(*choice == '2'){
		testInitializer();
		Printing("About to exec A2\n", ConsoleOutput, 0, 0);
		Exec("../test/testP4SuiteA2", 21);
		Printing("About to exec A1\n", ConsoleOutput, 0, 0);
		Exec("../test/testP4SuiteA1", 21);
	}
	else if(*choice == '3'){
		testInitializer();
		Printing("About to exec B1\n", ConsoleOutput, 0, 0);
		Exec("../test/testP4SuiteB1", 21);
		Printing("About to exec B2\n", ConsoleOutput, 0, 0);
		Exec("../test/testP4SuiteB2", 21);
		Printing("About to exec B3\n", ConsoleOutput, 0, 0);
		Exec("../test/testP4SuiteB3", 21);
	}
	else if(*choice == '4'){
		testInitializer();
		Printing("About to exec C1\n", ConsoleOutput, 0, 0);
		Exec("../test/testP4SuiteC1", 21);
	}
	else if(*choice == '5'){
		Printing("About to exec D1\n", ConsoleOutput, 0, 0);
		Exec("../test/testP4SuiteD1", 21);
		Printing("About to exec D2\n", ConsoleOutput, 0, 0);
		Exec("../test/testP4SuiteD2", 21);
		Printing("About to exec D3\n", ConsoleOutput, 0, 0);
		Exec("../test/testP4SuiteD3", 21);
	}
	else if(*choice == '6'){
	}
	else if(*choice == '7'){
	}
	else if(*choice == '8'){
	}
	else if(*choice == '9'){
	}
	else{
		Write("Error handling input.\n", 22, ConsoleOutput);
	}
	return;
}

int main(){
Printing("P4 Test Suite started\n", ConsoleOutput, 0, 0);
menu();

	Exit(0);

return;
}